package com.lamdba;// Java program to demonstrate the example
// of divideAndRemainder() method of BigDecimal

import java.math.*;

public class DivideAndRemainderOfBD {
    public static void main(String args[]) {
        // Initialize three variables divi1,
        // divi2 and str 
        int divi1 = 12000;
        int divi2 = 10000;
        String str = "5.6";

        // Initialize three BigDecimal objects and
        // one MathContext
        BigDecimal b_dec1 = new BigDecimal(divi1);
        BigDecimal b_dec2 = new BigDecimal(divi2);
        BigDecimal b_dec3 = new BigDecimal(str);
        MathContext ma_co = new MathContext(3, RoundingMode.CEILING);
        System.out.println("divideAndRemainder(BigDecimal): ");
        
        // divides this BigDecimal (b_dec1) by the
        // given BigDecimal (b_dec2) and return the BigDecimal[]
        // of two values (Quotient, Remainder)
        BigDecimal[] div_rem = b_dec1.divideAndRemainder(b_dec2);
        System.out.println("Quotient div_rem[0]: " + div_rem[0]);
        System.out.println("Remainder div_rem[1]: " + div_rem[1]);
        System.out.println(" ");

        System.out.println("divideAndRemainder(BigDecimal,MathContext): ");

        // divides this BigDecimal (b_dec1) by the
        // given BigDecimal (b_dec3) based on the given context setting
        // and return the BigDecimal[] of two values (Quotient, Remainder)
        div_rem = b_dec1.divideAndRemainder(b_dec3, ma_co);
        System.out.println("Quotient div_rem[0]: " + div_rem[0]);
        System.out.println("Remainder div_rem[1]: " + div_rem[1]);
    }
}

